/**
 * 
 */
package org.opencare.plugins.model;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.abdera.Abdera;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Document;
import org.apache.abdera.parser.Parser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.opencare.lib.model.Constants;
import org.opencare.lib.model.ExtensionFactory;
import org.opencare.lib.model.edxl.EDXLDistribution;

/**
 * @author nontster
 *
 */
public class AbderaMessageBuilderImpl implements MessageBuilder,Constants {

	protected final Log logger = LogFactory.getLog(getClass());
	
	private Abdera abdera;
	private Factory factory;
	private Parser parser;
	
	public AbderaMessageBuilderImpl() {
		super();
		// TODO Auto-generated constructor stub
		abdera = new Abdera();
		parser = abdera.getParser();		
		factory = abdera.getFactory();
		factory.registerExtension(new ExtensionFactory());
		
	}
	
	/* (non-Javadoc)
	 * @see org.opencare.plugins.model.MessageBuilder#build(java.lang.String)
	 */
	@Override
	public List<MessageObject> build(String xmlSource) {
		// TODO Auto-generated method stub
		
		MessageObject messageObj = new MessageObject();
		
		StringReader in = new StringReader(xmlSource);
		Document<EDXLDistribution> doc = parser.parse(in);	
		EDXLDistribution edxl = (EDXLDistribution) doc.getRoot();
	
		edxl.getDistributionID();
		edxl.getSenderID();
		edxl.getDistributionStatus();				
		edxl.getDistributionType();
		edxl.getCombinedConfidentiality();
		edxl.getLanguage();
			
		return new ArrayList<MessageObject>();
	}
}
